package 剑指offer;

public class _39数组中出现次数超过一半的数字 {
    public int majorityElement(int[] nums) {
        if(nums == null || nums.length <= 0) {
            return -1;
        }
        int res = nums[0];
        int count = 1;
        for(int i = 1; i < nums.length; i++) {
            if(count == 0) {
                res = nums[i];
                count++;
            }else if(res == nums[i]) {
                count ++;
            } else {
                count--;
            }
        }
        return res;
    }
}
